package tc.de.krawallmann.robobridge;

import java.util.HashSet;
import java.util.Set;

public class MultiState {

	/** The listeners. */
	protected final transient Set<MultiStateListener> listeners = new HashSet<MultiStateListener>();
	/** The state. */
	protected transient int state;
	/** The states. */
	protected final transient int states;

	/**
	 * Adds the state listener.
	 * 
	 * @param listener
	 *            the listener
	 * @return true, if successful
	 */
	public boolean addStateListener(final MultiStateListener listener) {
		return listeners.add(listener);
	}

	/**
	 * Clear state listeners.
	 */
	public void clearStateListeners() {
		listeners.clear();
	}

	/**
	 * Gets the state.
	 * 
	 * @return the state
	 */
	public int getState() {
		return state;
	}

	public MultiState(int states) {
		super();
		this.states = states;
	}

	/**
	 * Removes the state listener.
	 * 
	 * @param listener
	 *            the listener
	 * @return true, if successful
	 */
	public boolean removeStateListener(final MultiStateListener listener) {
		return listeners.remove(listener);
	}

	/**
	 * Reset.
	 */
	public void reset() {
		state = 0;
	}

	/**
	 * Sets the state.
	 * 
	 * @param state
	 *            the new state
	 */
	public void setState(final int state) {
		this.state = state;
	}

}
